<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';

if($_SESSION[usertype]!="recruiter"){
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
	exit;
}

require_once './include/advisory_db.php';
$status = $_SESSION['status'];
$isTr = 'Trial' != $status && 'Standard' != $status;
$smarty->assign('isTr',$isTr);
//print_r($_SESSION);
$smarty->compile_check = true;

//del

if($_GET[action]=='del'){
	if(!empty($_POST[del])){
	  foreach($_POST[del] as $value){
	     $str[] = "`jo_id` = '".$value."' ";
	  }
	  $where = @implode(' OR ',$str);
	  $sql = "DELETE FROM pa_job WHERE ($where) AND jo_utype = '".$_SESSION[usertype]."' AND jo_uid = '".$_SESSION[uid]."' ";
	  $DB->query($sql);
	}
	   echo "<meta http-equiv=\"refresh\" content=\"0;URL=myjobs.php\">";
	   exit;
}

$smarty->display('header.tpl');


$where = "  WHERE `jo_utype`='".$_SESSION[usertype]."' AND `jo_uid`='".$_SESSION[uid]."' ";

$by    = "a.jo_id"; 
$order = "DESC" ;
if($_GET[tp]==1){
	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "a.jo_id";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "a.jo_contact";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "a.jo_regtime";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "a.jo_status";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "a.jo_title";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "a.jo_status";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	    case 7:
		   $by = "count";
		   if($_GET[order7]==1){$order_arr[7]=2; $order=" DESC  ";$image_arr[7] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[7]=1;$order=" ,app_ownid  ASC ";$image_arr[7] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
		$smarty->assign("order_arr",$order_arr);
		$smarty->assign("image_arr",$image_arr);

}
$order = "GROUP BY jo_id  ORDER BY $by $order";

//echo " SELECT COUNT(*) AS count FROM pa_job as a ,pa_applicant as b $where $order ";
$nav = new buildNav;
$nav->offset = "offset1";
$nav->limit=10;



$result = $DB->query(" SELECT COUNT(*) AS count FROM  pa_applicant as b RIGHT JOIN pa_job as a ON a.jo_id = b.app_jobid $where $order");
$count = 0;
while($list = $DB->fetch_array($result)){
  $count++;
}

//echo "SELECT COUNT(*) AS count,a.*,b.* FROM pa_applicant as b RIGHT JOIN pa_job as a ON a.jo_id = b.app_jobid $where $order";
$nav->total_result = $count;
$nav->execute("SELECT COUNT(*) AS count,a.*,b.* FROM pa_applicant as b RIGHT JOIN pa_job as a ON a.jo_id = b.app_jobid $where $order");
$i=0;
while($list2 = $DB->fetch_array($nav->sql_result)){
   $datajob[$i]              = $list2;
   $datajob[$i][jo_state]    = $state[$list2[jo_state]];
   $datajob[$i][jo_country]  = $country[$list2[jo_state]];
   $datajob[$i][jo_function] = $jobfunction[$list2[jo_function]];
   if(preg_match("/2|3/",$list2[jo_contact])){
		$datajob[$i][jo_posttonetwork] = '<font color="orange">Posted</font>';
   }elseif($list2[jo_status] == 3){
		$datajob[$i][jo_posttonetwork] = 'Closed';
   }else{
		$datajob[$i][jo_posttonetwork] = 'Private';
   }
   $datajob[$i][jo_status]   = $jobfillstatus[$list2[jo_status]];
   $datajob[$i][jo_priority] = $priority[$list2[jo_priority]];
   $datajob[$i][jo_type]     = $jobtype[$list2[jo_type]];
   $datajob[$i][jo_regtime]  = @date("m/d/Y",$list2[jo_regtime]);
   $datajob[$i][jo_vdate]    = ($list2[jo_vdate] != '')?@date("m/d/Y",strtotime($list2[jo_vdate])):" - ";
   $datajob[$i][jo_applicants] = getNumberOfApplicants($datajob[$i][jo_id]);
   $datajob[$i][jo_contacts] = getNumberOfContacted($datajob[$i][jo_id]);
   $datajob[$i][jo_approved] = getNumberOfApproved($datajob[$i][jo_id]);
   if($datajob[$i][jo_applicants] < 1 && $datajob[$i][jo_contacts] < 1){
      $datajob[$i][candel] = 1;
   }
   $i++;
}
$smarty->assign("joblist",$datajob);
$page = $nav->pagenav();
$smarty->assign("page",$page);

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$smarty->assign('jobupdate_names',$UPDATE);

//print_r($findjob_orderby3);

$where = "  WHERE a.jo_id = b.app_jobid AND b.app_resumeid = c.re_id AND b.app_recruitid = '".$_SESSION[uid]."' ";

$by    = "b.app_id"; 
$order = "DESC" ;
if($_GET[tp]==2){
	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "a.jo_id";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "b.app_regtime";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "a.jo_title";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "a.jo_copname";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "a.jo_status";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "a.jo_salrange";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 7:
		   $by = "count";
		   if($_GET[order7]==1){$order_arr[7]=2; $order=" DESC ";$image_arr[7] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[7]=1;$order=" ASC ";$image_arr[7] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
		$smarty->assign("order_arr2",$order_arr);
		$smarty->assign("image_arr2",$image_arr);

}
$order = " GROUP BY jo_id  ORDER BY $by $order";

//echo "SELECT * FROM pa_job $where $order";
$nav = new buildNav;
$nav->offset = "offset2";
$nav->limit=5;
$nav->other="#li";
//echo "SELECT COUNT(*) AS count FROM pa_job as a ,pa_applicant as b , pa_resume as c $where $order";
$result = $DB->query("SELECT COUNT(*) AS count FROM pa_job as a ,pa_applicant as b , pa_resume as c $where $order");

$count2 = 0;
while($list = $DB->fetch_array($result)){
  $count2++;
}

$nav->total_result = $count2;
$nav->execute("SELECT COUNT(*) AS count, b.*,a.jo_copname,a.jo_id,a.jo_title,a.jo_salrange,a.jo_status,c.re_fname,c.re_lname FROM pa_job as a ,pa_applicant as b , pa_resume as c $where $order");

$i=0;
while($list2 = $DB->fetch_array($nav->sql_result)){
   $datajob2[$i]                = $list2;
   $datajob2[$i][id]            = $list2[app_id];
   if($list2[app_regtime]!=''){
	   $datajob2[$i][app_regtime] = date("m/d/Y h:i:s A",$list2[app_regtime]);
   }
   $datajob2[$i][title]         = $list2[jo_title];
   $datajob2[$i][status]        = $jobfillstatus[$list2[jo_status]];
   $datajob2[$i][name]          = $list2[re_fname]." ".$list2[re_lname];
   $datajob2[$i][jo_applicants] = getNumberOfApplicants($datajob2[$i][jo_id],1);
   $datajob2[$i][jo_salrange]   = $list2[jo_salrange];
   $i++;
}

$smarty->assign("joblist2",$datajob2);
$page2 = $nav->pagenav();
$smarty->assign("page2",$page2);


//count
$smarty->assign("postnum", $count);
$smarty->assign("submitnum", $count2);
$smarty->assign("offset2",$_GET[offset2]);


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$where = "  WHERE a.jo_id = b.re_aliasid AND b.re_uid = '".$_SESSION[uid]."' ";

$by    = "b.re_regtime"; 
$order = "DESC" ;
if($_GET[tp]==3){
	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "a.jo_id";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "b.re_regtime";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "a.jo_title";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "a.jo_copname";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "a.jo_status";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "b.re_isapproved";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 7:
		   $by = "count";
		   if($_GET[order7]==1){$order_arr[7]=2; $order=" DESC ";$image_arr[7] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[7]=1;$order=" ASC ";$image_arr[7] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
		$smarty->assign("order_arr3",$order_arr);
		$smarty->assign("image_arr3",$image_arr);

}
$order = " GROUP BY a.jo_id  ORDER BY $by $order";

//echo "SELECT * FROM pa_job $where $order";
$nav = new buildNav;
$nav->offset = "offset3";
$nav->limit=5;
$nav->other="#lii";
//echo "SELECT COUNT(*) AS count FROM pa_job as a ,pa_applicant as b , pa_resume as c $where $order";
$result = $DB->query("SELECT COUNT(*) AS count FROM pa_job as a ,pa_contact as b $where $order");
$count3 = 0;
while($list = $DB->fetch_array($result)){
  $count3++;
}

$nav->total_result = $count3;
$nav->execute("SELECT COUNT(*) AS count,b.*,SUM(b.re_isapproved) as re_isapproved,a.jo_copname,a.jo_id,a.jo_title,a.jo_salrange,a.jo_status, a.jo_regtime FROM pa_job as a ,pa_contact as b $where $order");

$i=0;
while($list3 = $DB->fetch_array($nav->sql_result)){
   $datajob3[$i]                = $list3;
   if($list3[re_regtime]!=''){
	   $datajob3[$i][re_regtime] = date("m/d/Y",$list3[re_regtime]);
   }
   $datajob3[$i][title]         = $list3[jo_title];
   $datajob3[$i][status]        = $jobfillstatus[$list3[jo_status]];
   $datajob3[$i][jo_applicants] = getNumberOfContacted($datajob3[$i][jo_id],1);
   $sql = "SELECT count(*) as count FROM pa_applicant WHERE app_jobid='".$list3['jo_id']."' AND app_recruitid ='".$_SESSION['uid']."' AND app_owntype='recruiter' ";
   $appInfo = $DB->fetch_one_array($sql);
   $datajob3[$i]['appcount'] = ($appInfo['count']>0)?'<a href="applicantlist.php?id='.$list3['jo_id'].'">'.$appInfo['count'].'</a>':0;
   $i++;
}
$smarty->assign("joblist3",$datajob3);
$page3 = $nav->pagenav();
$smarty->assign("page3",$page3);


//count
$smarty->assign("contactnum", $count3);
$smarty->assign("offset3",$_GET[offset3]);

$smarty->display('allleft.tpl');
$smarty->display('myjobs.tpl');
$smarty->display('footer.tpl');
?>